/*
 * =====================================================================================
 *
 *       Filename:  PowerAdapter.cc
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  08/20/21 15:04:05
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  XXXXXXX (), XXXX@jd.com
 *        Company:  JDAI
 *        Copyright:  Copyright 2021, XXXXXXX
 *
 * =====================================================================================
 */

#include <string>

#include "PowerAdapter.h"
#include "Log.h"

using std::string;

static const string TAG = "PowerAdapter";

PowerAdapter::PowerAdapter() {
    LogD("new");
    mspForeignSocketAdaptee = make_shared < ForeignSocketAdaptee > ();
    mspChinaSocketAdaptee = make_shared < ChinaSocketAdaptee > ();
}

PowerAdapter::~PowerAdapter() {
    LogD("del");
}

bool PowerAdapter::Charging12V() {
    LogI("In");

    switch (mPowerType) {
    case kPower110V:
        mspForeignSocketAdaptee->Charging12V();
        break;

    case kPower220V:
        mspForeignSocketAdaptee->Charging12V();
        break;

    default:
        return false;
    }

    return true;
}

bool PowerAdapter::SetPowerMode(PowerType type) {
    mPowerType = type;
    return true;
}

bool PowerAdapter::SetSocket(ISocketSPtr& socket) {
    LogD("In, mPowerType=%d", mPowerType);
    mspSocket = socket;

    switch (mPowerType) {
    case kPower110V:
        mspForeignSocketAdaptee->SetSocket(socket);
        break;

    case kPower220V:
        mspChinaSocketAdaptee->SetSocket(socket);
        break;

    default:
        break;
    }

    LogD("Out");
    return true;
}
